package com.wlc.base.design.single;

/**
 * @author 王立朝 wanglichao@champion-credit.com
 * @description 单例模式
 * @date 2021-09-16 16:42
 */
public class SingleDemo04 {
    /**
     * 枚举类
     */


    public static SingleDemo04 getInstance() {
        return Demo2.INSTANCE.singleDemo04;
    }

    /**
     * 定义枚举类
     */
    private static enum Demo2 {
        INSTANCE;
        /**
         * 枚举元素为单例
         */
        private SingleDemo04 singleDemo04;

        Demo2() {
            singleDemo04 = new SingleDemo04();
            System.out.println("枚举内部类启动");
        }

        public SingleDemo04 getInstance() {
            return singleDemo04;
        }
    }

    public static void main(String[] args) {
        SingleDemo04 s1 = SingleDemo04.getInstance();
        SingleDemo04 s2 = SingleDemo04.getInstance();
        System.out.println(s1.toString().equals(s2.toString()));
    }
}
